﻿using UnityEngine;
using System.Collections;

/**
 * Messenger.Broadcast<string>("MessageBoxError","请输入正确内容！");
 * 
 * */

public class MessageBox : MonoBehaviour {
	private UILabel _errorText;
	private Transform _boxTran;
	// Use this for initialization
	void Start () {
		_boxTran = transform.FindChild ("Panel/Box");
		_errorText=transform.FindChild("Panel/Box/Error_text").GetComponent<UILabel>();
		AddEventListObj1 (_boxTran.FindChild("Bt"));
		Messenger.AddListener<string> ("MessageBoxError",Error);
		_boxTran.gameObject.SetActive(false);
	}
	void AddEventListObj1(Transform tran)
	{
		//Debug.Log ("MainMc=" + obj.name);
		foreach (Transform child in tran)
		{
			child.gameObject.AddComponent<UIEventListener>();
			//child.gameObject.AddComponent<UIPlaySound>().audioClip= Resources.Load("Sounds/Tap")as AudioClip;
			Debug.Log("name----="+child.gameObject.name);
			UIEventListener.Get(child.gameObject).onClick = ButtonClick;
		}
	}
	// Update is called once per frame
	void Update () {
	
	}
	void ButtonClick(GameObject obj)
	{
		if(obj.name=="Bt_OK")
		{
			_errorText.text="";
			_boxTran.gameObject.SetActive(false);
		}
	}
	public string SetErrorText
	{
		get{
			return _errorText.text;
		}set{
			_errorText.text=value;
		}
	}
	private void Error(string str)
	{
		_errorText.text = str;
		_boxTran.gameObject.SetActive(true);
	}
}
